import { defHttp } from '/@/utils/http/axios';

const Restful = {
  list(url, params) {
    return defHttp.get({
      url: '/view/' + url + '/list',
      params: params
    });
  },
  get(url, params) {
    if (typeof params === 'number') {
      params = {
        id: params
      };
    }
    return defHttp.get({
      url: '/view/' + url + '/get',
      params: params
    });
  },
  columns(url, params) {
    if (typeof params === 'number') {
      params = {
        id: params
      };
    }
    return defHttp.get({
      url: '/view/' + url + '/columns',
      params: params
    });
  },
  // 新增一个表单数据
  post(url, params) {
    return defHttp.post({
      url: '/view/' + url + '/post',
      params: params
    });
  },
  // 没有变化的值也更新，多用于表单
  put(url, params) {
    return defHttp.put({
      url: '/view/' + url + '/put',
      params: params
    });
  },
  // 更新单个字段
  patch(url, params) {
    return defHttp.put({
      url: '/view/' + url + '/patch',
      params: params
    });
  },
  // 移动到回收站
  trash(url, params) {
    return defHttp.delete({
      url: '/view/' + url + '/trash',
      params: {
        ids: params
      }
    });
  },
  // 彻底删除
  clean(url, params) {
    return defHttp.delete({
      url: '/view/' + url + '/clean',
      params: {
        ids: params
      }
    });
  },
  // 恢复
  recovery(url, params) {
    return defHttp.delete({
      url: '/view/' + url + '/recovery',
      params: {
        ids: params
      }
    });
  }
};

export default Restful;
